package org.zjh.view.game;

import org.zjh.constant.ImageConstant;
import org.zjh.controller.listener.FrameCloseLis;
import org.zjh.model.Player;
import org.zjh.utils.FrameAndPanelUtil;
import org.zjh.view.register.RegisterPanel;
import org.zjh.view.ui.GameUi;

import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

/**
 * @description: TODO
 * @author 郑佳豪
 * @date 2024/10/24 12:59
 * @version 1.0
 */
public class GameOverFrame extends JFrame {
    //定义窗口宽度大小
    public static final int WIDTH = 800;
    //定义窗口高度大小
    public static final int HEIGHT = 500;


    private Player curDiscardPlayer;
    private GameOverPanel gameOverPanel;

    public GameOverFrame(Player curDiscardPlayer){
        this.curDiscardPlayer = curDiscardPlayer;
        //调用初始化构造方法
        init();
        //调用监听器注册方法
        addListener();
    }

    /**
     * 初始化
     */
    private void init(){
        setLayout(new BorderLayout());
        // 设置窗口的大小
        setSize(WIDTH,HEIGHT);
        //创建登入面板
        gameOverPanel = new GameOverPanel(curDiscardPlayer);
        //设置居中显示
        setLocationRelativeTo(null);
        // 设置关闭操作
        setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        //设置窗口标题
        setTitle("欢乐斗地主");
        // 设置窗口不可调节大小
        setResizable(false);
        //添加面板
        add(gameOverPanel);
        //设置窗口图片LOGO
        setIconImage(ImageConstant.Frame_Title_IMAGE.getImage());
        //设置窗口不可见
        setVisible(true);
    }


    private void addListener(){
        addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                int choice = JOptionPane.showConfirmDialog(null, "是否关闭", "温馨提示", JOptionPane.YES_NO_OPTION);
                if (choice == 0){
                    GameOverFrame.this.dispose();
                    GameUi.gameFrame.getGamePanel().repaint();
                }
            }
        });
    }
}
